﻿/**
* ...
* @author alijayameilio
*/

package particling.emitter;

import particling.Particle;
import particling.AParticle;

class CircleParticleEmitter extends ParticleEmitter
{

	public var minRadius:Int;
	public var maxRadius:Int;
	
	private var _minRadius:Int;
	private var _maxRadius:Int;
	
	public function new(__particle:Particle) :Void
	{
		super(__particle);
		minRadius = 0;
		maxRadius = 0;
	}
	
	public override function calculateXYPos(__selectedParticle:AParticle) :Void
	{
		var xPosition:Float = 0;
		var yPosition:Float = 0;
		var rotation:Float = Std.random(360);
		var altitude:Float = minRadius + Std.random(maxRadius - minRadius);
		if (rotation < 180)
		{
			xPosition = x + Math.cos(Math.abs(rotation - 90) * Math.PI / 180) * altitude;
			if (rotation < 90)
			{
				yPosition = y - Math.sin(Math.abs(rotation - 90) * Math.PI / 180) * altitude;
			} else
			{
				yPosition = y + Math.sin(Math.abs(rotation - 90) * Math.PI / 180) * altitude;
			}
		} else
		{
			xPosition = x - Math.cos(Math.abs(270 - rotation) * Math.PI / 180) * altitude;
			if (rotation < 270)
			{
				yPosition = y + Math.sin(Math.abs(270 - rotation) * Math.PI / 180) * altitude;
			} else
			{
				yPosition = y - Math.sin(Math.abs(270 - rotation) * Math.PI / 180) * altitude;
			}
		}
		__selectedParticle.container.x = xPosition;
		__selectedParticle.container.y = yPosition;
	}
	
	
	private function get_minRadius():Int
	{
		return _minRadius;
	}
	private function set_minRadius(value:Int):Int
	{
		if (value > _maxRadius)
		{
			_maxRadius = value;
		}
		_minRadius = value;
		return value;
	}
	
	private function get_maxRadius():Int
	{
		return _maxRadius;
	}
	private function set_maxRadius(value:Int):Int
	{
		if (value > _minRadius)
		{
			_minRadius = value;
		}
		_maxRadius = value;
		return value;
	}
	
	
}